﻿using RazorEngine;
using RazorEngine.Templating;
using System.IO;

namespace NP.BPMReportPlatform.EmailHelper
{
    public class EmailAPPService : BPMReportPlatformAppService, IEmailAPPService
    {
        public EmailAPPService()
        {

        }

        /// <summary>
        /// 生成邮件模板
        /// </summary>
        /// <param name="templateName"></param>
        /// <returns></returns>
        public string GenerateEmailTemplate(string templateName)
        {
            var tplPath = Path.Combine(Directory.GetCurrentDirectory(), "EmailTemplate", templateName);
            var template = File.ReadAllText(tplPath);
            var emailHtml = Engine.Razor.RunCompile(template, template.GetHashCode().ToString(), null, "");

            return emailHtml;
        }

        /// <summary>
        /// 生成邮件模板
        /// </summary>
        /// <param name="templateName"></param>
        /// <returns></returns>
        public string GenerateEmailTemplate(string templateName, object model)
        {
            var tplPath = Path.Combine(Directory.GetCurrentDirectory(), "EmailTemplate", templateName);
            var template = File.ReadAllText(tplPath);
            var emailHtml = Engine.Razor.RunCompile(template, template.GetHashCode().ToString(), null, model);

            return emailHtml;
        }
    }
}
